//
//  LiuTabBarController.swift
//  LiuWeiBo
//
//  Created by 刘晓晨 on 2017/3/26.
//  Copyright © 2017年 刘晓晨. All rights reserved.
///Users/xiaoyu/Desktop/LiuWeiBo/LiuWeiBo/LiuWeiBo/Classes/View/Main/LiuTabBarController.swift:25:32: Cannot invoke initializer for type 'LiuHomeViewController' with no arguments

import UIKit

class LiuTabBarController: UITabBarController,LiuTabBarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        //设置tabbar
        let tabbar = LiuTabBar()
        
        //设置代理
        tabbar.cmoposeDelegate = self
        
        setValue(tabbar, forKey: "tabBar")
        
        //添加子视图
        addChildViewController(LiuHomeViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(LiuMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(LiuDiscoveryViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(LiuMineViewController(), imageName: "tabbar_profile", title: "我的")
        
        //添加撰写按钮
        
    }
    
    //重写add方法
    func addChildViewController(_ childController: UIViewController ,imageName:String ,title:String) {
        
        //设置分栏图片
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        
        //设置分栏title
        childController.title = title
        
        //设置tabbar文字颜色和大小
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 12)], for: .normal)
        
        //设置导航控制器
        let nav = LiuNavigationController(rootViewController: childController)

        //添加导航控制器
        addChildViewController(nav)
        
    }
    
    //实现代理方法
    func composeButtonAction() {
        
        //判断是否未登录状态
        if !LiuUserAccountViewModel.sharedUserAccountViewModel.isSuccessToken! {
            return
        }
        
        //创建撰写页面
        let senderView = SendView()
        
        senderView.show(viewController: self)
        
    }

}







